# Maintainer: Johannes Schindelin <johannes.schindelin@gmx.de>

_realname=connect
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.105
tag='e122d9bd28e1'
pkgrel=4
pkgdesc="Make socket connection using SOCKS4/5 and HTTP tunnel (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('GPL2+')
url="https://github.com/gotoh/ssh-connect"
options=('strip')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=(${_realname}-${pkgver}.tar.gz::"${url}/archive/${pkgver}.tar.gz"
        "0001-Make-it-relocatable.patch"
        "pathtools.c"
        "pathtools.h")
sha256sums=('96c50fefe7ecf015cf64ba6cec9e421ffd3b18fef809f59961ef9229df528f3e'
            '1e1c89159178349a75665fcb9dfb7639e477b9af32165a377dad54c55e8a59d3'
            '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd'
            '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6')

prepare() {
  test ! -d "${startdir}/../mingw-w64-pathtools" || {
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.c" "${srcdir}/pathtools.c" &&
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.h" "${srcdir}/pathtools.h"
  } || exit 1

  cd "${srcdir}/ssh-connect-${pkgver}/"

  cp -fHv "${srcdir}"/pathtools.[ch] ./

  patch -p1 -i "${srcdir}/0001-Make-it-relocatable.patch"
}

build() {
  cd "${srcdir}/ssh-connect-${pkgver}"

  test -x ver || printf '#!/bin/sh\n\necho Windows\n' > ver

  PATH=.:$PATH make -j1 rebuild CC=cc
}

package() {
  cd "${srcdir}/ssh-connect-${pkgver}"

  install -d "${pkgdir}${MINGW_PREFIX}/bin/"
  install connect.exe "${pkgdir}${MINGW_PREFIX}/bin/"

  install -d "${pkgdir}${MINGW_PREFIX}/share/doc/connect/"
  install doc/manual.html "${pkgdir}${MINGW_PREFIX}/share/doc/connect/"
  install doc/manual.txt "${pkgdir}${MINGW_PREFIX}/share/doc/connect/"
}
